#include "game.h"
#include "main.h"
#include "key_control.h"
#include "display.h"
#include <random>

void start_game() {
  tmap = mat_char(32, std::vector<char>(32, 0));
  tsnake = Snake();
  tsnake.init_draw();
  food();
  is_play = true;
  is_play_init = true;
}
void time_loop(int p) {
  key_operations();
  // display();
  if (is_play && is_play_init) {
    tsnake.auto_move();
  }
  show_score();
  show_speed();
  // std::cout << speed_time << "\t";
  // fflush(stdout);

  glutTimerFunc(speed_time, time_loop, 0);
}
void game_over() {
  std::cout << "Game Over !\n";
  is_over = true;
  is_play = false;
  is_play_init = false;
  speed_time = 200;

  print_string("Game Over !", 320, 400);
}
void food() {
  int fx = rand() % 32;
  int fy = rand() % 32;
  while (tmap[fx][fy] != 0) {
    fx = rand() % 32;
    fy = rand() % 32;
  }
  // int fx = 30;
  // int fy = 30;
  // if (tmap[fx][fy] != 0) {
  //   fx = 10;
  //   fy = 10;
  // }
  tmap[fx][fy] = 'f';

  glPointSize(t_size); // 设置点大小
  glBegin(GL_POINTS);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2i(fx * 25 + 12, fy * 25 + 12);
  glEnd();
  glFlush();
}